#!/bin/bash

read -p "Local host login: " choice

# 定义变量

user="tom"
userpwd="tom"

# 根据输入值 进行条件判断

if [ $choice == $user ]; then
    read -p "password: " password
    if [ $password == $userpwd ]; then
        # tom登录成功
        # last login faile time
        # echo welcome to 版本号
        if [ -f 'login.txt' ]; then
            echo "last login: $(tail -1 login.txt)"
        fi
        if [ -f 'failed.txt' ]; then
            echo "login failed : $(tail -1 failed.txt)"
        fi
        echo "Welcome to $(cat /etc/issue)"
        echo $(date +"%Y-%m-%d %H:%M:%S") >>login.txt
    else
        echo 'login failed'
        echo "$(date +"%Y-%m-%d %H:%M:%S")" >>failed.txt
    fi
else
    read -p "password: " password
    echo "$(date +"%Y-%m-%d %H:%M:%S")" >>failed.txt
fi